<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <style>
        ul {
            list-style: none;
            padding: 0;
            margin: 0;
            width: 450px;
        }
        ul li {
            /* border-bottom: 1px solid #000; */
            /* 弹性盒子 */
            display: flex;
            justify-content: space-between;
            height: 50px;
            margin-top: 10px;
        }
        ul li .left {
            width: 260px;
            border: 1px solid #ccc;
            text-align: center;
            line-height: 50px;
            background-color: orange;
            font-size: 30px;
        }
        ul li .right {
            width: 120px;
        }
        ul li .right button {
            width: 120px;
            height: 50px;
            background-color:transparent;
            outline: none;
            border: 1px solid #ccc;
            cursor: pointer;
        }
    </style>
</head>
<body>

    <ul>
        <li>
            <div class="left">3楼</div>

            <div class="right"><button data-index="0">按钮</button></div>
        </li>

        <li>
            <div class="left">2楼</div>

            <div class="right"><button data-index="1">按钮</button></div>
        </li>

        <li>
            <div class="left">1楼</div>

            <div class="right"><button data-index="2">按钮</button></div>
        </li>

    </ul>

    <script>
        // 步骤：
            // 1获取标签
            // 2事件绑定
            // 3处理逻辑


     // 编码：
            // 1获取标签
            var leftItems = document.querySelectorAll(".left");
            var buttonItems = document.querySelectorAll(".right button");
            // 2事件绑定
            // buttonItems[0].onclick = function(){
            //      // 3处理逻辑
            //     // buttonItems[0].style.backgroundColor = "#ccc";
            //     this.style.backgroundColor = "#ccc";

            //     // leftItems[0].style.backgroundColor = "#ccc";
            //     // console.log(this.dataset);
            //     var index = this.dataset.index;
            //     leftItems[index].style.backgroundColor = "#ccc";
            // }


            buttonItems[0].onclick = function(){
                 // 3处理逻辑
                buttonItems[0].style.backgroundColor = "#ccc";
                leftItems[0].style.backgroundColor = "#ccc";
            }


            buttonItems[1].onclick = function(){
                 // 3处理逻辑
                buttonItems[1].style.backgroundColor = "#ccc";
                leftItems[1].style.backgroundColor = "#ccc";
            }

            buttonItems[2].onclick = function(){
                 // 3处理逻辑
                buttonItems[2].style.backgroundColor = "#ccc";
                leftItems[2].style.backgroundColor = "#ccc";
            }

           

    </script>
</body>
</html>